/**
 * Created by csch
 *
 * 数据字典工具类
 */
import store from "@/store"

export function getDictDatas(dictType) {
  return store.getters.dictMap[dictType] || []
}

export function getDictOpts(dictType) {
  return getDictDatas(dictType)
}

export function getDictOptions(dictType, valueType) {
  const dictOption = []
  const dictOptions = getDictDatas(dictType)
  if (dictOptions && dictOptions.length > 0) {
    dictOptions.forEach((dict) => {
      dictOption.push({
        ...dict,
        key: dict.value,
        value:
          valueType === 'string'
            ? `${dict.value}`
            : valueType === 'boolean'
              ? `${dict.value}` === 'true'
              : Number.parseInt(`${dict.value}`),
      })
    })
  }
  return dictOption
}

export function getDictObj(dictType, value) {
  const dictOptions = getDictDatas(dictType)
  let dictData = null
  if (dictOptions) {
    dictOptions.forEach((dict) => {
      if (dict.value === value.toString()){
        dictData = dict
      }
    })
  }
  return dictData
}

export const DICT_TYPE = {
	
	BUILDING_TYPE: 'building_type', // 建筑物类型
	
}
